﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using XMLGener.Data;
using XMLGener.interfaces;

namespace XMLGener.GUI.components
{
    public partial class XNumberItem : UserControl,IXModuleField
    {
        /// <summary>
        /// 
        /// </summary>
        public XNumberItem()
        {
            InitializeComponent();
        }

        /// <summary>
        /// This component can be also used as float editor.
        /// For this purpose can be set decimal places of number seletor.
        /// </summary>
        /// <param name="value"></param>
        public void setDecimalPlaces(int value)
        {
            this.numericUpDown1.DecimalPlaces = value;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="param"></param>
        public void setAttr(XModuleParam param)
        {
            this.label1.Text = param.name;
            this.id = param.id;
            this.numericUpDown1.Maximum = decimal.MaxValue;
            this.numericUpDown1.Minimum = decimal.MinValue;
        }


        private string id = null;
        private XMLGenerNode node = null;

        #region IXModuleField Members

        /// <summary>
        /// Set source nodes
        /// </summary>
        /// <param name="node"></param>
        public void setXNode(XMLGenerNode node)
        {
            this.node = node;
            if (node != null)
            {
                this.numericUpDown1.Value = Convert.ToDecimal(node.getSetting(id));
            }
        }


        #endregion

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            if (node != null)
                node.setSetting(id,Convert.ToString(this.numericUpDown1.Value));
            
        }
    }
}
